package main.com.cyz.Recursion;

/**
 * @author fox
 * @version 1.0
 * @description 冒泡排序 - 递归
 * @date 2024/5/17 10:29
 */
public class BubbleSort {

    public void sort(int[] nums) {
        r(nums, nums.length - 1);
    }

    public void r(int[] nums, int index) {
        if (index == 0) {
            return;
        }
        int x = 0;
        for (int i = 0; i < index; i++) {
            if (nums[i] > nums[i+1]){
                int temp = nums[i];
                nums[i] = nums[i+1];
                nums[i+1] = temp;
                x = i;
            }
        }
        r(nums,x);
    }

}
